<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text">
<input type="button" value="平方" onclick="f()">
<input type="button" value="相加" onclick="f1()">
<h3>
    结果：<span>

</span>
</h3>
<script>
    let i = document.querySelector("input");
    let s = document.querySelector("span");
    function f() {
       if(isNaN(i.value)){
           s.innerText = "输入错误！";
           return;
       }
       //字符串在进行-*、运算时会自动转成数值类型
        s.innerText=i.value*i.value;
    }
    function f1() {
        if(isNaN(i.value)){
            s.innerText="输入错误！";
            return;
        }
        s.innerText=parseFloat(i.value)+parseFloat(i.value);
    }
</script>
</body>
</html>